package Joueur;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class GroupPlayerTest extends TestCase {

	GroupPlayer groupPlayer;
	GroupPlayer.GroupIterator groupIterator;

	@Before
	public void setUp() {
		groupPlayer = new GroupPlayer(5);
		groupIterator = groupPlayer.getIterator();
		groupPlayer.addPlayer(null, null, 0);
		groupPlayer.addPlayer(null, null, 0);
		groupPlayer.addPlayer(null, null, 0);
		groupPlayer.addPlayer(null, null, 0);
		groupPlayer.addPlayer(null, null, 0);
	}

	@After
	public void tearDown() {
		groupPlayer = null;
		groupIterator = null;
	}

	@Test
	public void testGroupIterator() {
		int i = 0;
		while (groupIterator.hasNext()) {
			groupIterator.next();
			++i;
		}
		assertTrue(i == 5);
		groupIterator.next(); // passage au prochain tour
		i = 0;
		while (groupIterator.hasNext()) {
			groupIterator.next();
			++i;
		}
		assertTrue(i == 4);
	}

	@Test
	public void testRemovePlayer() {
		Player p = groupIterator.next();
		p = groupIterator.next();
		p = groupIterator.next();
		// les variables static ne se reset pas dans les units test
		groupIterator = groupPlayer.getIterator();

		assertTrue(p.getId() % groupPlayer.getPlayerList().size() == 2);

		groupPlayer.removePlayer(p);

		assertTrue(groupPlayer.nbPlayerGroup() == 4);

		while (groupIterator.hasNext()) {
			Player pl = groupIterator.next();
			assertTrue(pl.getId() != 2);
		}
	}

}
